﻿using Abp.Authorization.Users;
using Abp.Domain.Entities;
using shenghua.Authorization.Users;
using shenghua.Common.CustomValueType;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shenghua.Member.Members
{
    /// <summary>
    /// 会员
    /// </summary>
    public class Member: User
    {
        public static Member CreateMember(string userName, string name, string phone, string email)
        {
            Member member = new Member
            {
                UserName = userName,
                NormalizedUserName = userName.ToUpper(),
                EmailAddress = email,
                NormalizedEmailAddress = email.ToUpper(),
                IsEmailConfirmed = true,
                PhoneNumber = phone,
                IsPhoneNumberConfirmed = true,
                Name = name,
                Surname = "",
                Level = 1
            };
            return member;
        }

        /// <summary>
        /// 累计积分
        /// </summary>
        public int TotalXPValue { get; set; }

        /// <summary>
        /// 积分值
        /// </summary>
        public int XPValue { get; set; }

        public int Level { get; set; }

        public ValueArray<string> Groups { get; set; }

        public Dictionary<string, string> FormItems
        {
            get
            {
                return this.GetData<Dictionary<string, string>>("formitems");
            }
        }

        public void SetFormItems(Dictionary<string, string> formItems)
        {
            this.SetData("formitems", formItems);
        }

        public string Remark { get; set; }

        public MemberStatus Status { get; set; }

        public Member()
        {
            Groups = new ValueArray<string>();
            SetFormItems(new Dictionary<string, string>());
            UserType = Authorization.Users.UserType.Member;
        }
    }

    public enum MemberStatus
    {
        PendingAudit = 0,
        Audited = 1,
        AuditFailed = 2
    }
}
